<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import ="java.sql.*" %>
<%@ page import = "java.io.*" %>
<%@page import = "java.util.Properties" %>
<%@page import = "java.util.ArrayList" %>
<%@page import = "persistency.Price_CRUD" %>


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Display price information from the table 'Price' of the DB 'MiniServiceDesk'</title>
</head>
<body>
	<h1>Verificatie van de connectie met de databank </h1>
	
	<%
	Connection con = null;  
	Statement stmt1 = null;
	Statement stmt2 = null;
	ResultSet rs = null;
	ResultSetMetaData header = null;
	int numberOfColumns;
	String dBUser;
	Price_CRUD crud = new Price_CRUD();
	try{
		//moet onderstaande best in afzonderlijke klassen gestoken worden? 
		String fileName = application.getInitParameter("DB");
		InputStream stream = application.getResourceAsStream(fileName);
		Properties props = new Properties();     
		props.load(stream); 
		Class.forName(props.getProperty("DATABASE_TYPE")).newInstance();
		String dBURL= props.getProperty("DATABASE_URL");
		dBUser = props.getProperty("DATABASE_USER");
		String dBPwd = props.getProperty("DATABASE_PWD");
		con =DriverManager.getConnection (dBURL,dBUser,dBPwd);%>
		De DB USER is: <%= dBUser %>
		<%}catch (Exception e)
		{
		%>
		Onvoorziene fout
		<% e.toString();%> 
		in pagina<br>
	  <%} %>
	  
	<% 
	//of moet onderstaande via de persistency datalayer?
		stmt1 = con.createStatement();
		//Price_CRUD crud = new Price_CRUD();
    	//rs = stmt.executeQuery(request.getParameter("Query"));
		rs = stmt1.executeQuery("select * from Price");
		//rs = crud.getAll().;
	%>
		
	<center>
			<h2>Price List "All Prices" </h2>
			<table border="1" cellspacing="0" cellpadding="0">
			<tr>
				<%
				header = rs.getMetaData(); 
    			numberOfColumns = header.getColumnCount();
    			for (int i = 1; i <= numberOfColumns; i++){
    			%>
    			<th>
    			<%= header.getColumnName(i)%>
    			</th>
    			<%} %>
    		</tr>
    		<% 
    		
    		while (rs.next())
    		{		
    		%>
    			<tr>
    			<% 
    			for (int i = 1;i <= numberOfColumns; i++)
    				{
    				%>
    				<td>
    				<%=  rs.getObject(i)%> 
    				</td>
    			   <%}%>
    			</tr>
    	   <% }
    	   //rs.close();
		   //stmt1.close();
	       //con.close();
	       %>
    		</table>
			</center>
			<br>
			
			Het aantal prijs objecten in de databank bedraagt: <%=crud.getCount()%>
			<br>
	<%
		//stmt2 = con.createStatement();		
		rs = stmt1.executeQuery("select * from Price where active = true");
	%>
		
	<center>
			<h2>Price List "All Active Prices" </h2>
			<table border="1" cellspacing="0" cellpadding="0">
			<tr>
				<%
				header = rs.getMetaData(); 
    			numberOfColumns = header.getColumnCount();
    			for (int i = 1; i <= numberOfColumns; i++){
    			%>
    			<th>
    			<%= header.getColumnName(i)%>
    			</th>
    			<%} %>
    		</tr>
    		<% 
    		
    		while (rs.next())
    		{		
    		%>
    			<tr>
    			<% 
    			for (int i = 1;i <= numberOfColumns; i++)
    				{
    				%>
    				<td>
    				<%=  rs.getObject(i)%> 
    				</td>
    			   <%}%>
    			</tr>
    	   <% }
    	   rs.close();
		   stmt1.close();
	       con.close();
	       %>
    		</table>
			</center>
			<br>
			
</body>
</html>